package com.qf.service.impl;


import com.qf.common.AliyunOSSConstants;
import com.qf.common.UpdateRefundDetailParams;
import com.qf.entity.OrderRefundDetail;
import com.qf.entity.OrderRefundDetailVO;
import com.qf.mapper.OrderRefundDetailMapper;
import com.qf.service.OrderRefundDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * 天--道--酬--勤
 *
 * @author LiangGaoQiang
 * @ClassName OrderRefundDetailServiceImpl
 * @Date: 2025/5/3 11:47
 * @Description: 描述
 */
@Service
public class OrderRefundDetailServiceImpl implements OrderRefundDetailService {
    @Autowired
    private OrderRefundDetailMapper orderRefundDetailMapper;


    @Override
    public List<OrderRefundDetailVO> getRefundInfo(Long refundId) {
        return orderRefundDetailMapper.getRefundInfo(refundId);
    }

    @Override
    public boolean updateRefundDetail(String filePath, Long refundId) {
        // 将图片路径存储到数据库中
        // 1. 截取图片路径的最后一部分作为图片名称
        String proofImage = filePath.substring(AliyunOSSConstants.PUBLIC_URL.length());

        // 2. 查询出所有的以 refundId 为条件的数据
        List<Long> refundIds = orderRefundDetailMapper.getRefundByRefundId(refundId);

        // 3. 如果 refundIds 为空，则不需要更新
        if (refundIds == null || refundIds.isEmpty()) {
            return false;
        }

        // 4. 创建 UpdateRefundDetailParams 对象
        UpdateRefundDetailParams params = new UpdateRefundDetailParams();
        params.setProofImage(proofImage);
        params.setRefundIds(refundIds);

        // 5. 执行更新操作
        boolean result = orderRefundDetailMapper.updateRefundDetail(params);
        return result;
    }
}
